﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using AimGameEngine.EditorObject;

using AimGameLibrary;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeBoolean : NodeBaseControl
    {
        public Boolean myboolean;
        public NodeBoolean(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw, MyListUpdateTime, MyListObject, MyListType)
        {
            myboolean = false;

            Connecter outputInt = new Connecter(inputspritebatch, inputcamera, Syco.Output, NodeTypeValue.Boolean, this);
            ListConnectpoint.Add(outputInt);
        }

        public override void SetupInput(Connecter Thisconnect, Connecter connectOutput)
        {
            if (this.InputMode == NodeInputMode.Boolean_1)
                this.MyData.Data = connectOutput.MyNode.MyData.MyName;
        }

        public override void ClearInput(Connecter ThisInputConnect, Connecter ThisConnectClear, string NameThisClear)
        {
            //base.ClearInput(ThisConnectClear, NameThisClear);
            MyData.Data = MyData.Data.Replace(NameThisClear, "NULL");
        }

        public override void ShowProprety(ArrayList Temp, CallBack input)
        {
            base.ShowProprety(Temp, input);
            PropretyBoolean propretyboolean = new PropretyBoolean(this);
            //propretyboolean.Deactivate += new EventHandler(input.Deactivate);
            propretyboolean.okButton.Click += new EventHandler(input.Deactivate);
            propretyboolean.ShowDialog();
            
        }

        public override void SetupProprety()
        {
            base.SetupProprety();

            if (InputMode == NodeInputMode.Boolean_1)
            {
                Connecter inputInt = new Connecter(this.spritebatch, this.camera, Syco.Input, NodeTypeValue.Boolean, this);
                ListConnectpoint.Add(inputInt);
            }

            this.AfterSetupProprety();
        }

        protected override Dictionary<string, NodeObject> GetDictionaryNode(Dictionary<string, NodeObject> TempNode)
        {
            if (this.MyData.Data != null)
            if (this.MyDictionaryObject.ContainsKey(this.MyData.Data))
                TempNode.Add(this.MyData.Data, this.MyDictionaryObject[this.MyData.Data]);

            return base.GetDictionaryNode(TempNode);
        }

        public override void SaveData(System.Collections.ArrayList Thislist, SaveMode inputsavemode)
        {
            base.SaveData(Thislist,inputsavemode);

            Thislist.Add(InputMode);
            Thislist.Add(myboolean);
        }

        public override void LoadData(Identification getdata, int IndexData)
        {
            base.LoadData(getdata, IndexData);

            if (getdata.Items.GetValue(IndexData + 1).GetType() == typeof(NodeInputMode))
            InputMode = (NodeInputMode)getdata.Items.GetValue(IndexData + 1);

            if (getdata.Items.GetValue(IndexData + 2).GetType() == typeof(Boolean))
            myboolean = (Boolean)getdata.Items.GetValue(IndexData + 2);

            SetupProprety();
        }
    }
}
